<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

class LinkModel extends Model
{
    //
    protected $table = 'link';

    public $timestamps = false;

    //插入友情链接
    public function insertLink($data) {
        $res = self::insert($data);
        return $res;
    }

    //获取所有的链接
    public function getLinks() {
        $res = self::get()->toArray();
        return $res;
    }

    //获取一条链接
    public function getLink($id) {
        $res = self::find($id)->toArray();
        return $res;
    }

    //更新链接
    public function upLink($id , $data) {
        $res = self::where('id' , $id)->update($data);
        return $res;
    }

    //删除链接
    public function delLink($id) {
        $res = self::destroy($id);
        return $res;
    }

    //获取链接并排序
    public function getLinksBySort() {
        $res = self::select('title' , 'url')
                        ->orderBy('sort' , 'asc')
                        ->get()
                        ->toArray();
        return $res;
    }
}
